package softtech.apps.callblocker;


import android.R.integer;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;

public class ListenerPhone {
	private TelephonyManager mtelephony ;
	private String mExtraState;
	private String mPhoneNumber;
	/**
	 * constructor 
	 * @param context 
	 * @param intent
	 * Create object TelephonyManager and get string state phone
	 */
	public ListenerPhone(Context context, Intent intent) {
		
		//Create Telephony Manager
		mtelephony = (TelephonyManager) context
				.getSystemService(Context.TELEPHONY_SERVICE);
		//Getting extra state
		mExtraState = intent
						.getStringExtra(TelephonyManager.EXTRA_STATE);
	}
	/**
	 * check incoming call
	 * @return 1 if incoming call
	 */
	public int fIncomingCall(){
		if(mExtraState.equals(TelephonyManager.EXTRA_STATE_RINGING)){
			return 1;
		}
		return 0;
	}
	/**
	 * Check idle call
	 * @return 1 if idle 
	 */
	public int fIdleCall(){
		if(mExtraState.equals(TelephonyManager.EXTRA_STATE_IDLE)){
			return 1;
		}
		return 0;
	}
	/**
	 * get phone number incoming call
	 * @param intent: incoming call
	 * @return : phone number incoming cal
	 */
	public String fgetPhoneNumber(Intent intent){
		mPhoneNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
		return mPhoneNumber;
	}
	/**
	 * Get TelephonyManager
	 * @return
	 */
	public TelephonyManager getMtelephony() {
		return mtelephony;
	}
	/**
	 * Set TelephonyManager
	 * @param mtelephony
	 */
	public void setMtelephony(TelephonyManager mtelephony) {
		this.mtelephony = mtelephony;
	}
	
}
